<?php

namespace App\Models\Traits;

use Illuminate\Database\Eloquent\Builder;

trait HasUserGoldBean
{
	public function isGoldBeansEnough($beans): bool
	{
		$unpaidRecordBeans = $this->myUnpaidRecordsBeans();
		$needBeans = big_decimal($beans)->plus($unpaidRecordBeans);
		return $needBeans->isLessThanOrEqualTo($this->gold_beans);
	}

	public function hasGoldBeansRecords(): bool
	{
		return $this->goldBeans()->exists();
	}

	public function hasNoGoldBeansRecords(): bool
	{
		return !$this->hasGoldBeansRecords();
	}

	public function hadSupportedGoldBeans(): bool
	{
		return $this->goldBeans()
			->where(function (Builder $query) {
				$query->where('remark', 'support_gold_beans')
					->orWhere('remark', 'transfered_in_beans')
					->orWhere('remark', 'present_gold_beans');
			})->exists();
	}
}
